<template>
  <div class="currentPage">
    <!-- <router-link tag='button' to="/index">登录</router-link> -->

    <div class="part1">
      <img src="@/assets/logo.png" alt="">
    </div>
    <div class="part2">
      <div class="login-box">
        <div class="title">瑜音葫芦丝后台管理系统</div>
        <div class="user">
          <i class="el-icon-user"></i> <input type="text" placeholder="请输入教师证工号" v-model="user" @keyup.enter="login">
        </div>
        <div class="password">
          <i class="el-icon-unlock"></i> <input type="password" placeholder="请输入密码" v-model="password" @keyup.enter="login">
        </div>
        <div style="text-align:right;margin:30px;">
          <el-checkbox v-model="checked" @change="change"><span style="color:#333">记住用户名</span></el-checkbox>
        </div>
        <div class="btn" @click="login">登录</div>
      </div>
      <div class="img">
        <img src="@/assets/bg.png" alt="">
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      avtiveName: 'first',
      checked: false,
      user: 'admin',
      password: '123456'
    }
  },
  created() {
    if (window.localStorage.getItem('remember')) {
      this.checked = true
      let userName = window.localStorage.getItem('userName')
      if (userName) {
        this.user = userName
      }
    }
  },
  methods: {
    change(e) {
      if (e) {
        window.localStorage.setItem('remember', true)
      } else {
        window.localStorage.removeItem('remember')
      }
    },
    login() {
      if (this.user.trim() === '' || this.password.trim() === '') {
        this.$showTips('请输入用户名或密码', 'error')
        return
      }
      if (this.checked) {
        window.localStorage.setItem('userName', this.user)
      }

      var pa = {
        "userName": this.user,
        "password": this.password,
        "accountType": 0,
        "platform": 0,
        "verifyCode": {
          "id": "string",
          "code": "string"
        }
      }
      this.$api.adminlogin(pa).then(res => {
        if (res.code == 1) {
          window.localStorage.setItem('isLogin', true)
          window.localStorage.setItem('access_token', res.data.accessToken)
          this.$router.replace('/index')
          this.$showTips("登录成功")
          this.$api.videogetsign('').then(res => {
            console.log(res);
            window.localStorage.setItem("uploadSign",res)
          })
        } else {
          this.$showTips(res.msg, 'error')
        }
      })

    }
  }
}
</script>

<style scoped lang='scss'>
.currentPage {
  min-width: 1024px;
}
.part1 {
  width: 150px;
  height: 150px;
  // border: 1px solid;
  padding: 30px;
  font-size: 40px;
  font-weight: 900;
  img {
    width: 100%;
    height: 100%;
  }
}
.part2 {
  display: flex;
  justify-content: space-around;
  height: calc(100vh - 100px);
  align-items: center;
  margin-top: -100px;
  .login-box {
    // border: 1px solid;
    width: 420px;
    text-align: center;
    i {
      font-size: 20px;
      color: rgba($color: gray, $alpha: 0.6);
    }
    .title {
      font-size: 20px;
      font-weight: 700;
    }
    .user {
      margin: 50px 0;
    }
    input {
      border: none;
      outline: none;
      padding: 5px 20px;
      width: 300px;
      border-bottom: 1px solid rgba($color: gray, $alpha: 0.2);
      font-size: 16px;
    }
    .btn {
      padding: 12px 0;
      border-radius: 30px;
      background: #85bdfe;
      color: #fff;
      cursor: pointer;
      &:hover {
        opacity: 0.8;
      }
    }
  }
}
</style>